package com.burke.gwt.client;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.dom.client.ImageElement;

public class Floater {
	  ImageElement image;
	  ImageElement standImage;
	  ImageElement jumpImage;
	  double rot;
	  public Vector pos, vel, target;
	  double jumpHeight;
	  
	  double a = 0.15;//0.25;
	  double maxA = 3;
	  
	  public int state;
	  
	  public int frame;

	  public Floater(ImageElement image) {

	    this.image = image;

	    this.rot = 0;
	    jumpHeight = 0;
	    
	    pos = new Vector(0,0);
	    
	    target = new Vector(0,0);
	    
	    vel = new Vector(0,0);
	    
	    vel.y = -1 * (Math.random());
	    vel.x = Math.random() -0.5;
	    
	  }
	  
	  public void draw(Context2d context) {
        context.save();
	    context.translate(this.pos.x, this.pos.y);

	    context.drawImage(image, 0, 0);
	    context.restore();
	  }
	  
	  public void update(Vector t) {
		  
		  target = t;
		  
		  if (pos.y < target.y) {
			  vel.y += a;
			  if (vel.y > maxA) vel.y = maxA;
		  }
		  else {
			  vel.y -= a;
			  if (vel.y < -maxA) vel.y = -maxA;
		  }
		  
		  
		  if (target.x < pos.x) {
			  vel.x -= a;
			  if (vel.x < -maxA) vel.x = -maxA;
		  }
		  else {
			  vel.x += a;
			  if (vel.x > maxA) vel.x = maxA;
		  }
		  
		  pos.x += vel.x;
	  
		  pos.y += vel.y;
		  
	  }
	  

}
